// 引入express
const express = require("express");

// 引用controller
const pagesController = require("./controllers/pagesController.js");
const userController = require("./controllers/userController.js");
const postsController = require("./controllers/postsController.js");
const cateController = require("./controllers/cateController.js");
const uploadController = require("./controllers/uploadController.js");
const optionsController = require("./controllers/optionsController.js");

// 创建路由
var router = express.Router();

// 后台页面
router
  .get("/admin", pagesController.getAdminIndexPage)
  .get("/admin/categories", pagesController.getAdminCategoriesPage)
  .get("/admin/comments", pagesController.getAdminCommentsPage)
  .get("/admin/login", pagesController.getAdminLoginPage)
  .get("/admin/nav-menus", pagesController.getAdminNavMenusPage)
  .get("/admin/password-reset", pagesController.getAdminPasswordResetPage)
  .get("/admin/post-add", pagesController.getAdminPostAddPage)
  .get("/admin/posts", pagesController.getAdminPostsPage)
  .get("/admin/profile", pagesController.getAdminProfilePage)
  .get("/admin/settings", pagesController.getAdminSettingsPage)
  .get("/admin/slides", pagesController.getAdminSlidesPage)
  .get("/admin/users", pagesController.getAdminUsersPage)

  // 前台页面
  .get("/", pagesController.getIndexPage)
  .get("/detail", pagesController.getDetailPage)
  .get("/list", pagesController.getListPage)

  // 业务处理路由
  .post("/login", userController.login)

  .get("/getAllPosts", postsController.getAllPosts)
  .post("/addPost", postsController.addPost)
  .get("/getPostById", postsController.getPostById)
  .post("editPostById", postsController.editPostById)
  .get("/dalPostById", postsController.delPostById)

  .get("/getAllCate", cateController.getAllCate)
  .post("/editCate", cateController.editCate)
  .post("/addCate", cateController.addCate)
  .get("/delCateById", cateController.delCateById)

  .post("addMenu", optionsController.addMenu)
  .get("/getSettings", optionsController.getSettings)
  .post("/updateSettings", optionsController.updateSettings)

  // 文件上传
  .post("/uploadFile", uploadController.uploadFile);

module.exports = router;
